<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace AlibabaCloud\Client\Credentials\Ini;

trait CreateTrait
{
    protected function createClient($clientName, array $credential)
    {
        if(!isset($credential["enable"]) || !$credential["enable"]) {
            return false;
        }
        if(!isset($credential["type"])) {
            $this->missingRequired("type", $clientName);
        }
        return $this->createClientByType($clientName, $credential)->name($clientName);
    }
    private function createClientByType($clientName, array $credential)
    {
        strtolower($credential["type"]);
        switch (strtolower($credential["type"])) {
            case "access_key":
                return $this->accessKeyClient($clientName, $credential);
                break;
            case "ecs_ram_role":
                return $this->ecsRamRoleClient($clientName, $credential);
                break;
            case "ram_role_arn":
                return $this->ramRoleArnClient($clientName, $credential);
                break;
            case "bearer_token":
                return $this->bearerTokenClient($clientName, $credential);
                break;
            case "rsa_key_pair":
                return $this->rsaKeyPairClient($clientName, $credential);
                break;
            default:
                throw new \AlibabaCloud\Client\Exception\ClientException("Invalid type '" . $credential["type"] . "' for '" . $clientName . "' in " . $this->filename, \AlibabaCloud\Client\SDK::INVALID_CREDENTIAL);
        }
    }
    private function accessKeyClient($clientName, array $credential)
    {
        if(!isset($credential["access_key_id"])) {
            $this->missingRequired("access_key_id", $clientName);
        }
        if(!isset($credential["access_key_secret"])) {
            $this->missingRequired("access_key_secret", $clientName);
        }
        return new \AlibabaCloud\Client\Clients\AccessKeyClient($credential["access_key_id"], $credential["access_key_secret"]);
    }
    private function ecsRamRoleClient($clientName, array $credential)
    {
        if(!isset($credential["role_name"])) {
            $this->missingRequired("role_name", $clientName);
        }
        return new \AlibabaCloud\Client\Clients\EcsRamRoleClient($credential["role_name"]);
    }
    private function ramRoleArnClient($clientName, array $credential)
    {
        if(!isset($credential["access_key_id"])) {
            $this->missingRequired("access_key_id", $clientName);
        }
        if(!isset($credential["access_key_secret"])) {
            $this->missingRequired("access_key_secret", $clientName);
        }
        if(!isset($credential["role_arn"])) {
            $this->missingRequired("role_arn", $clientName);
        }
        if(!isset($credential["role_session_name"])) {
            $this->missingRequired("role_session_name", $clientName);
        }
        return new \AlibabaCloud\Client\Clients\RamRoleArnClient($credential["access_key_id"], $credential["access_key_secret"], $credential["role_arn"], $credential["role_session_name"]);
    }
    private function bearerTokenClient($clientName, array $credential)
    {
        if(!isset($credential["bearer_token"])) {
            $this->missingRequired("bearer_token", $clientName);
        }
        return new \AlibabaCloud\Client\Clients\BearerTokenClient($credential["bearer_token"]);
    }
    private function rsaKeyPairClient($clientName, array $credential)
    {
        if(!isset($credential["public_key_id"])) {
            $this->missingRequired("public_key_id", $clientName);
        }
        if(!isset($credential["private_key_file"])) {
            $this->missingRequired("private_key_file", $clientName);
        }
        return new \AlibabaCloud\Client\Clients\RsaKeyPairClient($credential["public_key_id"], $credential["private_key_file"]);
    }
}

?>